/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.jmarias.client.tcp;

import com.google.code.jmarias.common.action.AbstractAction;
import com.google.code.jmarias.common.action.ChooseFromPeopleAction;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 *
 * @author Ondrej Michal &lt;ondrej.michal@netvoice.cz&gt;
 */
public class NewClass4 {


    public static void main(String[] args) throws FileNotFoundException, ScriptException, NoSuchMethodException, ClassNotFoundException {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        List<String> actions = new ArrayList<String>();
        engine.put("actions", actions);

        // evaluate a script string. The script accesses "file"
        // variable and calls method on it
        engine.eval(new FileReader("/home/ondra/jmarias-backup-localcopy/jmarias/client/src/main/resources/server.js"));

        Invocable inv = (Invocable) engine;
        
//        DealSevenCardsAction action = new DealSevenCardsAction(new Card[]{new Card(Suit.leaves, Value.ace), new Card(Suit.acorns, Value.ace), new Card(Suit.leaves, Value.ace), new Card(Suit.hearts, Value.ace), new Card(Suit.acorns, Value.ace), new Card(Suit.hearts, Value.overKnave), new Card(Suit.hearts, Value.value7)});
        ChooseFromPeopleAction action = new ChooseFromPeopleAction();
//        PickedTrumpAction action = new PickedTrumpAction();
//        System.out.println(action.getClass().getSimpleName());
        String s = (String) inv.invokeFunction("process" + action.getClass().getSimpleName(), action);
        System.out.println("dalsi faze: " + s);

//        Object obj = engine.get("phase");
//        inv.invokeMethod(obj, "processPickedTrumpAction", action);
//        System.out.println("obj: " + obj.getClass().getCanonicalName());
//        inv.invokeMethod(obj, "asdf");
//        System.out.println("actions: " + actions);
//
//        Class cl = Class.forName("java.lang.String");
//        System.out.println(cl.getSimpleName());
        State state = new State();
        inv.invokeFunction("addSupportedActions", state);
        System.out.println("rec: " + state.getRecipient());
        System.out.println("trans: " + state.getTransitions());
//        List<Class> classes = new ArrayList<Class>();
//        for (String actionName : list) {
//            classes.add(Class.forName(AbstractAction.class.getPackage().getName() + "." + actionName));
//        }
    }
}
